<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__container}">
      <div class="ba-operate-form">
        <el-form :model="dataForm" @keyup.enter.native="getDataList()" label-width="70px">
          <el-row :gutter="20">
            <el-col :md="6" :sm="6">
              <el-form-item label="托盘条码">
                <el-input v-model="dataForm.contNo" placeholder="精确匹配" maxlength="32" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="6">
              <el-form-item label="托盘类型">
                <el-input v-model="dataForm.contType" placeholder="精确匹配" maxlength="20" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="12" :sm="12">
              <div class="right-handle-group">
                <el-button-group>
                  <el-button @click="getDataList()" type="primary">{{ $t('query') }}</el-button>
                  <el-button @click="getReset()">{{ $t("reset") }}</el-button>
                </el-button-group>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="ba-operate-button">
        <el-form :inline="true">
          <el-form-item>
            <el-button v-if="$hasPermission('wms:container:save')" type="primary" @click="addOrUpdateHandle()">{{
              $t("add")
            }}</el-button>
          </el-form-item>
        </el-form>
      </div>

      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
        style="width: 100%">
        <el-table-column prop="contId" label="id" header-align="center" align="center" sortable></el-table-column>
        <el-table-column prop="contNo" label="托盘条码" header-align="center" align="center" min-width="220">
        </el-table-column>
        <el-table-column prop="contType" label="托盘类型" header-align="center" align="center" min-width="100"></el-table-column>
        <el-table-column prop="creatorName" label="创建用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
        <el-table-column prop="updaterName" label="更新用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="updateDate" label="更新日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./container-add-or-update";
import debounce from "lodash/debounce";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/container/page",
        getDataListIsPage: true,
        exportURL: "/wms/container/export",
        deleteURL: "/wms/container",
        deleteIsBatch: true,
      },
      dataForm: {
        contNo: '',
        contType: '',
        contDescription: '',
      },
      changeForm: {
        contId: "",
        status: "",
      },
    };
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
    },
    changeStatus: debounce(function (val, row) {
      var tempStatus = row.status === 0 ? 1 : 0;
      this.changeForm.contId = row.contId;
      this.changeForm.status = row.status;
      this.$http[!this.changeForm.contId ? "post" : "put"](
        "/wms/container/",
        this.changeForm
      )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            //如果更新失败则重置为原来的状态
            row.status = tempStatus;
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => { },
          });
        })
        .catch(() => { });
    }),
  },
};
</script>
